﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dqs_BLL;
using Dqs_DAL;
using Model;
using Sunny.UI;
namespace Dqs_UI
{
	public partial class frmUpdateClass : UIForm
	{
		public frmUpdateClass(int id)
		{
			InitializeComponent();
			this.Id = id;
		}

		int Id { get; set; }
		Class_BLL Class_BLL = new Class_BLL();

		private void frmUpdateClass_Load(object sender, EventArgs e)
		{
			//加载数据
			ClassInfo classInfo = Class_BLL.GetClasses().Where(a => a.Id == Id).FirstOrDefault()!;
			txtCourseName.Text = classInfo.ClassName;
			txtDescription.Text = classInfo.MaxCount.ToString();
			uiRadioButton1.Checked = classInfo.IsMultimedia;
			uiRadioButton2.Checked = !classInfo.IsMultimedia;
			uiRadioButton3.Checked = !classInfo.IsOccupied;
			uiRadioButton4.Checked = classInfo.IsOccupied;


		}

		private void uiButton1_Click(object sender, EventArgs e)
		{
			ClassInfo classInfo = new ClassInfo();
			classInfo.Id = Id;
			classInfo.ClassName = txtCourseName.Text.Trim();
			classInfo.MaxCount = Convert.ToInt32(txtDescription.Text.Trim());
			classInfo.IsMultimedia = uiRadioButton1.Checked ? true : false;
			classInfo.IsOccupied = uiRadioButton4.Checked ? true : false;

			if (Class_BLL.UpdateClassInfoById(classInfo))
			{
				DialogResult = DialogResult.OK;
			}
			else
			{
				MessageBox.Show("请检查输入内容是否正确！");
			}
		}

		private void uiButton2_Click(object sender, EventArgs e)
		{
			frmUpdateClass_Load(this, e);
		}
	}
}
